import re
import _lex as lex


kls=[ "and"          , "always"      , "assign"     , "begin"     , "buf"         ,
      "bufif0"       , "bufif1"      , "case"       , "casex"     , "casez"       ,
      "cmos"         , "deassign"    , "default"    , "defparam"  , "disable"     ,
      "edge"         , "else"        , "end"        , "endcase"   , "endfunction" ,
      "endprimitive" , "endmodule"   , "endspecify" , "endtable"  , "endtask"     ,
      "event"        , "for"         , "force"      , "forever"   , "fork"        ,
      "function"     , "highz0"      , "highz1"     , "if"        , "ifnone"      ,
      "initial"      , "inout"       , "input"      , "integer"   , "join"        ,
      "large"        , "macromodule" , "medium"     , "module"    , "nand"        ,
      "negedge"      , "nor"         , "not"        , "notif0"    , "notif1"      ,
      "nmos"         , "or"          , "output"     , "parameter" , "pmos"        ,
      "posedge"      , "primitive"   , "pulldown"   , "pullup"    , "pull0"       ,
      "pull1"        , "rcmos"       , "real"       , "realtime"  , "reg"         ,
      "release"      , "repeat"      , "rnmos"      , "rpmos"     , "rtran"       ,
      "rtranif0"     , "rtranif1"    , "scalared"   , "small"     , "specify"     ,
      "specparam"    , "strength"    , "strong0"    , "strong1"   , "supply0"     ,
      "supply1"      , "table"       , "task"       , "tran"      , "tranif0"     ,
      "tranif1"      , "time"        , "tri"        , "triand"    , "trior"       ,
      "trireg"       , "tri0"        , "tri1"       , "vectored"  , "wait"        ,
      "wand"         , "weak0"       , "weak1"      , "while"     , "wire"        ,
      "wor"          , "xnor"        , "xor"        , "logic"
      ];

f = open("lex.h","r")
kd={} 

for l in f:
    mat = re.match("#define\s+(\w+)\s+(\d+)",l)
    if(mat):
        kd[int(mat.group(2))] = mat.group(1)


f.close()
lex.setfile("/home/host/work/project/rtl/e203_hbirdv2/rtl/e203/core/e203_cpu.v")

tok = lex.yylex()
val = lex.get_string()
while(tok):
    if(tok>=200):
        print(kd[tok])
    else:
        print(kls[tok-1])
    print(val)
    tok = lex.yylex()
    val = lex.get_string()

